﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Parametros
{
    class Program
    {
        static void Main (string[] args)
        {
            var tracer      = string.Empty;
            var dirout      = string.Empty;
            var bins        = new List<string>();
            var resolvers   = new List<string>();
            
            var currentArg  = string.Empty;

            foreach (var arg in args)
            {
                if (arg.StartsWith("--"))
                {
                    currentArg = arg.Trim().Replace("--", "");
                }
                else if (arg.StartsWith("-"))
                {
                    currentArg = arg.Trim().Replace("-", "");
                }
                else
                {
                    switch (currentArg)
                    {
                        case "parasitracer":
                        case "p":
                            if (dirout != string.Empty)
                            {
                                ConsoleColor cc = Console.ForegroundColor;
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.Error.WriteLine("\"tracer\" parameter allready declared");
                                Console.ForegroundColor = cc;
                                usage();
                                Environment.Exit(-1);
                            }
                            tracer = arg;
                            break;
                        case "dirout":
                        case "o":
                            if (dirout != string.Empty)
                                throw new Exception("dirout parameter allready declared");
                            dirout = arg;
                            break;
                        case "bins":
                        case "b":
                            bins.Add(arg);
                            break;
                        case "resolvers":
                        case "r":
                            resolvers.Add(arg);
                            break;
                    }
                }
            }

            if (validar(tracer, dirout, bins))
            {
                Console.WriteLine("tracer= {0}", tracer);
                Console.WriteLine("dirout= {0}", dirout);

                Console.Write("bins=[ ");
                foreach (string binX in bins)
                    Console.Write("{0} ", binX);
                Console.WriteLine("]");

                Console.Write("resolvers=[ ");
                foreach (string resolverX in resolvers)
                    Console.Write("{0} ", resolverX);
                Console.WriteLine("]");
                // llamariamos a la libreria aca...
            }
            else
            {
                usage();
            }
        }

        private static bool validar (string tracer, string dirout, List<string> bins)
        {
            if (tracer == string.Empty)
                return false;

            if (dirout == string.Empty)
                return false;

            if (bins.Count < 1)
                return false;

            return true;
        }

        private static void usage ()
        {
            Console.WriteLine("ParasInject usage:");
            Console.WriteLine(" parasinject -p \"parasitracer path\" -o \"parasitracer out dir\" -b \"bin path 1\" [[\"bin path 2\"]...]  ");
        }
    }
}
